package src.com.doit.Demo07;

import java.util.ArrayList;
import java.util.Random;

public class GongSi {
    private double zongZiChan;
    private ArrayList<Employee> list;

    public GongSi() {
    }

    public GongSi(double zongZiChan, ArrayList<Employee> list) {
        this.zongZiChan = zongZiChan;
        this.list = list;
    }

    public void show() {
        System.out.println("公司总资产:" + zongZiChan + "元");
        //员工信息
        for (int i = 0; i < list.size(); i++) {
            System.out.println("姓名:" + list.get(i).getName());
            System.out.println("ID:" + list.get(i).getId());
            System.out.println("存款:" + list.get(i).getCunKuan() + "元");
            if (list.get(i) instanceof JingLi) {
                System.out.println("奖金:" + ((JingLi) list.get(i)).getJiangJin() + "元");
            }
            System.out.println("工资:" + list.get(i).getGongZi() + "元");
            System.out.println("----------------------------------------");
        }
    }
    public void add(Employee ee , double money)//加薪
    {
        System.out.println("为员工:"+ee.getName()+",加薪:"+money+"元");
        ee.setGongZi(ee.getGongZi()+money);
    }
    public void randomEmployee()
    {
        Random  r = new Random();
        int i = r.nextInt(list.size());
        System.out.println("幸运员工为:"+list.get(i).getName());
        add(list.get(i),50000);
        System.out.println("加薪后的工资为:"+list.get(i).getGongZi()+"元");
    }

    public void payoff() {

        for (int i = 0; i < list.size(); i++) {
            zongZiChan-=list.get(i).getGongZi();//总资产-工资
            list.get(i).setCunKuan(list.get(i).getCunKuan()+list.get(i).getGongZi());//发工资后的存款
            if (list.get(i) instanceof JingLi) {
                zongZiChan-=((JingLi) list.get(i)).getJiangJin();
                list.get(i).setCunKuan(list.get(i).getCunKuan()+list.get(i).getGongZi()+((JingLi) list.get(i)).getJiangJin());
            }
        }
    }

    public double getZongZiChan() {
        return zongZiChan;
    }

    public void setZongZiChan(double zongZiChan) {
        this.zongZiChan = zongZiChan;
    }

    public ArrayList<Employee> getList() {
        return list;
    }

    public void setList(ArrayList<Employee> list) {
        this.list = list;
    }
}
